import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:kxy_flutter_app/components/video_widget.dart';
import 'package:kxy_flutter_app/model/news_detail.dart';

class VideoNewsWidget extends StatefulWidget {
  final NewsDetail newsDetail;
  VideoNewsWidget({this.newsDetail});

  @override
  State<StatefulWidget> createState() {
    return VideoNewsWidgetState();
  }
}

class VideoNewsWidgetState extends State<VideoNewsWidget> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        VideoWidget(url: widget.newsDetail.videoUrl),
        title,
        info,
        detail,
      ],
    );
  }

  Widget get title {
    return Container(
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.only(top: 10),
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Text(
        widget.newsDetail.title,
        style: TextStyle(
          fontSize: 16,
        ),
      ),
    );
  }

  Widget get info {
    var format = new DateFormat('yyyy年MM月dd日发布');
    return Container(
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.only(top: 5),
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Text(
        '${widget.newsDetail.hits.toString()}人观看 | ${format.format(widget.newsDetail.createTime)}',
        style: TextStyle(
          fontSize: 13,
          color: Colors.black54,
        ),
      ),
    );
  }

  Widget get detail {
    return Container(
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.only(top: 20),
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: EdgeInsets.only(bottom: 10),
            child: Text(
              '简介',
              style: TextStyle(
                fontSize: 16,
                color: Colors.black87,
              ),
            ),
          ),
          Text(
            widget.newsDetail.brief,
            style: TextStyle(
              fontSize: 13,
              color: Colors.black54,
            ),
          ),
        ],
      ),
    );
  }
}
